#config
PAKAGE=tabtreemix-1.0.1
PATTERN="(chrome.manifest|\.xul|\.xml|\.js|\.dtd|\.properties|\.gif|\.css|\.rdf|\.png)$"


#$1 : folder $2 : dest
function cp_folder {
    
    src=$1
    dst=$2

    mkdir -p $dst

    for file in $src/*; do

        if [ -d $file ]; then
            if [ $file != $tdir ]; then
                (cp_folder $file $dst/`basename $file`)
            fi
        else
            echo $file | egrep "$PATTERN" > /dev/null
            if [ $? -eq 0 ]; then
                cp $file $dst
            else
                echo Ignore : $file
            fi
        fi
    done
}


#script
wdir=`dirname $0`
wdir=`(cd $wdir; pwd)`
tdir=$wdir/${PAKAGE}_TMP_REP

rm -rf ${tdir} ${PAKAGE}.xpi


cp_folder $wdir $tdir
cd $tdir
zip -rq $wdir/${PAKAGE}.xpi *

rm -rf $tdir

